"""Anonycoin --- Bitcoin simulator with anonymity throught group signature

Copyright (c) 2016 Daniel Pimentel <d4n1@member.fsf.org>

This file is part Anonycoin.

Anonycoin is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or (at
your option) any later version.

Anonycoin is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Anonycoin.  If not, see <http://www.gnu.org/licenses/>.
"""

import threading
from script import Script


class Transaction(threading.Thread):
    """Transaction Bitcoin simulator thread."""

    def __init__(self, inputs, outputs, btc):
        """Constructor.
        inputs - wallet input
        outputs - wallet output
        btc - btc amount
        """
        threading.Thread.__init__(self)
        self.inputs = inputs
        self.outputs = outputs
        self.btc = btc

    def make(self, simulation):
        """Make transacton.
        simulations - simulation type
        inputs - [transaction_hash, sign]
        outputs - [btc_value, hash_key]
        """
        transaction = Script()
        transaction_sign = transaction.sign(transaction.hash_key)
        self.inputs = [transaction.hash_key, transaction_sign]
        if simulation == 0:
            self.outputs = [self.btc, self.outputs.hash_key]
        if simulation == 1:
            group = Script()
            group_sign = group.sign(transaction.hash_key)
            self.outputs = [self.btc, group.hash_key]
